﻿using System;
using System.Web;

namespace ExtAspNet.Examples
{
    public partial class _default : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // 设置样式和语言下拉列表的选中值
                ddlTheme.SelectedValue = PageManager1.Theme.ToString().ToLower();
                ddlLanguage.SelectedValue = PageManager1.Language.ToString().ToLower();

                // 显示源代码按钮
                btnSourceCode.OnClientClick = windowSourceCode.GetShowReference("./source.aspx?files=default.aspx;menu.xml;Web.config;Code/PageBase.cs;js/default.js");

                // 绑定 XML 数据源到树控件
                treeMenu.DataSource = XmlDataSource1;
                treeMenu.DataBind();
            }
        }

        
        /// <summary>
        /// 修改样式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlTheme_SelectedIndexChanged(object sender, EventArgs e)
        {
            HttpCookie themeCookie = new HttpCookie("Theme", ddlTheme.SelectedValue);
            themeCookie.Expires = DateTime.Now.AddYears(1);
            Response.Cookies.Add(themeCookie);

            PageContext.Refresh();
        }

        /// <summary>
        /// 修改语言
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            HttpCookie langCookie = new HttpCookie("Language", ddlLanguage.SelectedValue);
            langCookie.Expires = DateTime.Now.AddYears(1);
            Response.Cookies.Add(langCookie);

            PageContext.Refresh();
        }

    }
}
